package com.sophon.pattern.observer.classic;

import java.util.HashSet;
import java.util.Set;

import com.sophon.pattern.observer.Observable;
import com.sophon.pattern.observer.Observer;

public class Mouse implements Observable {

	private Set<Observer> observers;

	public Mouse() {
		observers = new HashSet<Observer>();
	}

	public void registerObserver(String eventName, Observer o) {
		observers.add(o);
	}

	public void removeObserver(String eventName, Observer o) {
		observers.remove(o);
	}

	public void notifyObserver(Set<Observer> observers) {
		for (Observer o : observers) {
			o.doSomething();
		}
	}

	public void click() {
		System.out.println("鼠标单击");
		notifyObserver(observers);
	}
}
